#include "1-bit_node.hpp"

template<class T = int>
void printInOrderNode(BitNode<T>* p_node)
{
  if (p_node != nullptr) {
    int dep = getDepthTr(p_node);
    for (int i = 0; i < dep; ++i) {
      std::cout << "   " ;
    }
    std::cout << p_node->data << std::endl;
  }
}

template<class T = int>
void printBitTree(BitNode<T>* tree)
{
  if (tree == nullptr) {
    return;
  }

  printBitTree(tree->rchild);
  printInOrderNode(tree);
  printBitTree(tree->lchild);
}

template<class T = int>
class BitTree {
  public:
    BitTree() : tree(nullptr) {}
    explicit BitTree(BitNode<T>* _tree) : tree(_tree) {}
    virtual ~BitTree() { freeBitNode(tree); }

    void preOrder() { preLoopOrder(tree); }
    void inOrder() { inLoopOrder(tree); }
    void postOrder() { postLoopOrder(tree); }
    void levelOrder() { levelOrderTr(tree); }

    virtual int getHight() { return getHightTr(tree); }
    int getBalance() { return getBalanceTr(tree); }

    BitNode<T>* operator->() { return tree; }

    virtual void print() { 
      printBitTree(tree);
      // preOrder(); std::cout << std::endl;
      // inOrder(); std::cout << std::endl;
      std::cout << "------------------------------" << std::endl;
    }

  public:
    BitNode<T>* tree;
};

